import {forEach, isArray, isString} from "lodash-es";

export function updateTreeData(list, key, children) {
    if (!isArray(list)) {
        return [];
    }
    // debugger;
    return list.map(node => {
        if (node.key === key) {
            return {...node, children};
        }
        if (node.children) {
            return {...node, children: updateTreeData(node.children, key, children)};
        }

        return node;
    });
}

export function indexOfKeys(obj, keys, search) {
    let isOk = false;

    forEach(keys, (key) => {
        let val = obj[key];

        if (isString(val) && val.toUpperCase().indexOf(`${search}`.toUpperCase()) > -1) {
            isOk = true;
            return false; // 中断 forIn
        }
    });

    return isOk
}